//
//  RenHouseTopImageCell.m
//  CenturyCity
//
//  Created by beisheng03 on 2017/12/19.
//  Copyright © 2017年 beisheng. All rights reserved.
//

#import "RenHouseTopImageCell.h"
#import <SDCycleScrollView/SDCycleScrollView.h>

#import "RentHouseDetailVC.h"
#import "GoodDetailController.h"
#import "EmploymentDetailVC.h"

#import "AboutusController.h"
@interface RenHouseTopImageCell ()<SDCycleScrollViewDelegate>
@property (weak, nonatomic) IBOutlet UIView *bgView;

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *bottomMargin;
@property (nonatomic, weak) SDCycleScrollView *cycleView;
@end

@implementation RenHouseTopImageCell


- (void)setupTopScrollview{
    
    if (!_cycleView) {
        // 网络加载 --- 创建自定义图片的pageControlDot的图片轮播器
        SDCycleScrollView *cycleScrollView = [SDCycleScrollView cycleScrollViewWithFrame:CGRectMake(0, 0, KScreenW, KScreenW / 8.0 * 3) delegate:self placeholderImage:[UIImage imageNamed:@"placeholder"]];
        
        cycleScrollView.autoScrollTimeInterval = 3;
        cycleScrollView.pageControlStyle = SDCycleScrollViewPageContolStyleAnimated;
        cycleScrollView.pageControlAliment = SDCycleScrollViewPageContolAlimentRight;
        //    cycleScrollView3.currentPageDotImage = [UIImage imageNamed:@"pageControlCurrentDot"];
        //    cycleScrollView3.pageDotImage = [UIImage imageNamed:@"pageControlDot"];
        _cycleView = cycleScrollView;
        
        
        [self.bgView addSubview:_cycleView];
        
        
    }
    
    
}

- (void)awakeFromNib {
    [super awakeFromNib];
    
    [self setupTopScrollview];
//    [self.topImageView sd_setImageWithURL:[NSURL URLWithString:@"http://pic39.nipic.com/20140311/10600816_135850674000_2.jpg"] placeholderImage:nil];
    // Initialization code
}


- (void)setModels:(NSMutableArray<HousRentAdvsModel *> *)models{
    _models = models;
    
    self.cycleView.height = self.imageViewH; 
    
    self.cycleView.imageURLStringsGroup = [_models valueForKeyPath:@"adv_image"];

    
    
}


#pragma mark - SDCycleScrollViewDelegate

/** 点击图片回调 */
- (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index{
    
    HousRentAdvsModel *subModel = self.models[index];
    
    if ([subModel.class_id isEqualToString:@"1"]) {
        
        RentHouseDetailVC *temp = [[RentHouseDetailVC alloc]init];
        
        temp.houseId = subModel.ID;
        
        [self.viewController.navigationController pushViewController:temp animated:YES];
        
        
    } else if ([subModel.class_id isEqualToString:@"2"]){
        
        EmploymentDetailVC *tempVC = [[EmploymentDetailVC alloc]init];
        
        tempVC.IdStr = subModel.ID;
        
        [self.viewController.navigationController pushViewController:tempVC animated:YES];
        
    }else if ([subModel.class_id isEqualToString:@"3"]){
        
        GoodDetailController *tempVC = [[GoodDetailController alloc]init];
        
        OneGoodsModel *tempModel = [[OneGoodsModel alloc]init];
        
        tempModel.goods_id = subModel.ID;
        
        tempModel.goods_image_url = subModel.adv_image;
        
        tempVC.goodsModel = tempModel;
        
        [self.viewController.navigationController pushViewController:tempVC animated:YES];
        
        
    }else{
        
        AboutusController *temp = [[AboutusController alloc]init];
        
        temp.urlString = subModel.content;
        
        [self.viewController.navigationController pushViewController:temp animated:YES];
        
    }
    
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
